#!/bin/sh
echo $0 $*
XDG_DATA_HOME=${XDG_DATA_HOME:-$HOME/.local/share}

# 修改为直接获取文件夹名称的用法
ProjectName="dadg"
GAMEDIR="/mnt/SDCARD/Ports/$ProjectName"
# GAMEDIR=${PWD}
echo ==========GAMEDIR is $GAMEDIR
controlfolder="../PortMaster"

source $controlfolder/control.txt
#source $controlfolder/tasksetter

get_controls

# Enable logging
> "$GAMEDIR/log.txt" && exec > >(tee "$GAMEDIR/log.txt") 2>&1

CONFDIR="$GAMEDIR/conf/"

# Ensure the conf directory exists
mkdir -p "$GAMEDIR/conf"

# Set the XDG environment variables for config & savefiles
export XDG_CONFIG_HOME="$CONFDIR"
export XDG_DATA_HOME="$CONFDIR"

RUNTIME_DIR="$controlfolder/libs"

cd $GAMEDIR

GODOT_BINARY="frt_aarch64_3.5.2"
GODOT_OPTS="--resolution 1280x720 -f"
GODOT_RUN="$ESUDO $RUNTIME_DIR/$GODOT_BINARY $GODOT_OPTS"

$GPTOKEYB $GODOT_BINARY -c "$GAMEDIR/game.gptk" &
$GODOT_RUN --main-pack "gamedata/DnDG_64.pck" 


$ESUDO kill -9 $(pidof gptokeyb)
$ESUDO systemctl restart oga_events &
printf "\033c" > /dev/tty0